package leetcode.code0932;

import java.util.LinkedList;
import java.util.Queue;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int[] beautifulArray(int n) {
		if (n == 1) {
			return new int[] { 1 };
		}
		int[] ans = new int[n];
		int half = n >> 1;
		int leftsize = half, rightsize = half;
		if ((n & 1) == 1) {
			leftsize += 1;
		}
		int[] left = this.beautifulArray(leftsize);
		int[] right = this.beautifulArray(rightsize);
		int p = 0;
		for (int i = 0; i < left.length; i++) {
			ans[p++] = (left[i] << 1) - 1;
		}
		for (int i = 0; i < right.length; i++) {
			ans[p++] = right[i] << 1;
		}
		return ans;
	}

	@Override
	public void debug4() {
		H.print(this.beautifulArray(4));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
